<!-- 撤销入库 -->
<template>
  <view class="revocation">
    <view class="top">
      <van-cell-group>
        <van-field
          :value="purchaseinfo.purchase_sn_detail"
          label="入库编号："
          readonly
        ></van-field>
        <van-field
          :value="purchaseinfo.applyname"
          label="采购人姓名："
          readonly
        ></van-field>
        <van-field
          :value="purchaseinfo.purchase_reason"
          label="采购原因："
          readonly
        ></van-field>
      </van-cell-group>
    </view>
    <view class="content">
      <view class="list_box">
        <view class="list_item mb20" v-for="(item, index) in purchasegoodsinfo" :key="index">
          <view class="list_item_title flexb">
            <view class="name flexAI f28 fwbold">
              <view class="point br50 mr10"></view>
              <view>品名：{{ item.goods_name }}</view>
            </view>
            <view class="quantity">
              <text>数量：</text>{{ item.goods_num }} {{ item.unit_name }}
            </view>
          </view>
          <view class="time_box flexb">
            <view> 生产日期：{{ item.productiontime }} </view>
            <view> 保质期（天）：{{ item.assurancetime }} </view>
          </view>
          <view class="locations_unitrice-box flexb">
            <view> 产地：{{ item.address }} </view>
            <view class="unit_price">
              单价 ：<text>￥ {{ item.shop_price }}</text>
            </view>
          </view>
          <view class="details_subtotal-box flexb">
            <view class="subtotal f28 tc fwbold">
              小计:<text>￥{{ item.total_money }}</text>
              </view>
          </view>
        </view>
      </view>
      <view class="btn_style">
        <van-button color="#62B158" type="default" @click="goCancel" >撤销入库</van-button>
        <van-button color="#999999 " type="default" @click="off">关闭</van-button>
      </view>
    </view>
    <!-- 撤销原因 -->
    <van-overlay :show="disagreeShow">
      <view class="wrapper">
        <view class="block f28">
          <view class="title flexb f32">
            <view class="details fwbold">撤销原因 </view>
            <view class="icon" @click="offShow">
              <van-icon name="clear" color="#3E3D3D" size="20px" />
            </view>
          </view>
          <view class="content">
            <view class="textbox">
              <van-input
                rows="8"
                v-model="opinion"
                type="textarea"
                placeholder="请填写撤销原因"
                autosize
                :border="true"
                :norequired="true"
              ></van-input>
            </view>
            <view class="btn_style">
              <van-button color="#999999 " type="info" @click="cancel">取消</van-button>
              <van-button color="#62B158" type="info" @click="sumbit">提交</van-button>
            </view>
          </view>
        </view>
      </view>
    </van-overlay>
  </view>
</template>

<script>
export default {
  data() {
    return {
      purchase_sn_detail: "",
      purchaseinfo: {},
      purchasegoodsinfo: [],
      disagreeShow: false,
      opinion: "",
    };
  },
  onLoad(options) {
    this.purchase_sn_detail = options.purchase_sn_detail;
    if (this.purchase_sn_detail) {
      this.getRevokepurchasedetail();
    }
  },
  methods: {
    /*获取页面数据*/
    async getRevokepurchasedetail() {
      let res = await this.$ajax.onRevokepurchasedetail({
        purchase_sn_detail: this.purchase_sn_detail,
      });
      if (res.code == 1) {
        this.purchaseinfo = res.data.purchaseinfo;
        this.purchasegoodsinfo = res.data.purchasegoodsinfo;
      }
    },
    /*撤销入库弹框*/
    goCancel() {
      this.disagreeShow = true;
    },
    offShow() {
      this.disagreeShow = false;
      this.opinion = "";
    },
    cancel() {
      this.disagreeShow = false;
      this.opinion = "";
    },
    off() {
      uni.navigateTo({
        url: "../purchaseOrder/purchaseOrder",
      });
      this.opinion = "";
    },
    /*撤销原因*/
    async sumbit() {
        let res = await this.$ajax.onRevokepurchaseok({
          opinion: this.opinion,
          purchase_sn_detail: this.purchase_sn_detail,
        });
        if (res.code == 1) {
          this.disagreeShow = false;
          uni.showToast({
            title: res.msg,
            icon: "none",
            duration: 1000,
          });
          setTimeout(() => {
            uni.navigateTo({
              url: "../purchaseOrder/purchaseOrder",
            });
          }, 1000);   
        } else {
          uni.showToast({
            title: res.msg,
            icon: "none",
            duration: 1000,
          });
        }

    },
  },
  mounted() {},
};
</script>

<style lang="scss" scoped>
.revocation {
  min-height: 100vh;
  height: 100%;
  background: rgba(244, 244, 244, 1);

  .top {
    background: #ffffff;
    padding-bottom: 20rpx;
  }

  .content {
    margin-bottom: 50rpx;

    .list_box {
      .list_item {
        width: 100%;
        height: 300rpx;
        line-height: 55rpx;
        background-color: rgba(255, 255, 255, 1);
        color: rgba(16, 16, 16, 1);
        font-size: 28rpx;
        padding: 20rpx 20rpx;
        padding-bottom: 10rpx;
        font-family: SourceHanSansSC-regular;

        .list_item_title {

          .name {
            color: rgba(16, 16, 16, 1);
            font-family: SourceHanSansSC-bold;

            .point {
              width: 15rpx;
              height: 15rpx;
              background: rgba(98, 177, 88, 1);
            }
          }
        }

        .time_box {
        }

        .locations_unitrice-box {
          border-bottom: 0.5rpx solid #e7e4e4;
          padding-bottom: 20rpx;

          .unit_price {
            text {
              color: red;
            }
          }
        }

        .details_subtotal-box {
          padding-top: 20rpx;

          .subtotal {
            background-color: rgba(255, 255, 255, 1);
            color: rgba(209, 35, 18, 1);
            font-family: Arial;
          }
        }
      }
    }

    .btn_style {
      display: flex;
      justify-content: space-evenly;
      margin-top: 100rpx;
      padding-bottom: 100rpx;

      ::v-deep .van-button {
        width: 180rpx;
        height: 72rpx;
        border-radius: 8rpx;
        color: rgba(255, 255, 255, 1);
        font-size: 28rpx;
        text-align: center;
        font-family: Microsoft Yahei;
      }
    }
  }
}

// 弹框样式
.myover {
  z-index: 100 !important;

  .van-transition {
    z-index: 100 !important;
  }
}

.van-fade-enter-active {
  z-index: 99;
}

.wrapper {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;

  .block {
    width: 100%;
    background-color: #fff;
    margin: 0 30rpx;
    border-radius: 16px;
    padding: 40rpx 20rpx;

    .title {
      color: rgba(16, 16, 16, 1);
      font-family: SourceHanSansSC-bold;
      padding-bottom: 10rpx;

      .details {
      }
    }

    // 不同意
    .content {
      margin-bottom: 68rpx;

      .btn_style {
        display: flex;
        justify-content: space-evenly;
        margin-top: 66rpx;

        ::v-deep .van-button {
          width: 180rpx;
          height: 72rpx;
          border-radius: 8rpx;
          color: rgba(255, 255, 255, 1);
          font-size: 28rpx;
          text-align: center;
          font-family: Microsoft Yahei;
        }
      }
    }
  }
}
</style>